package com.itheima.array;

import java.util.Scanner;

public class ArrayIndex {
    public static void main(String[] args) {
        Scanner sc = new  Scanner(System.in);
        int[] arr ={12,35,56,61,98};
        System.out.println("请输入你要查询的数:");
        int num = sc.nextInt();
        //标记位:先定义一个索引变量,初始值位-1;假设查找的num在数组中不存在
        int index = -1;
        //遍历数组
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == num){
                //找到一样的,就修改标记.将当前索引位置元素的索引值记录
                index = i;
                System.out.println("index = " + index);
            }
        }

        if (index == -1){
            System.out.println("index = " + index);
        }
    }
}
